package com.westar.base.businessUtil;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.westar.core.conf.SysConst;
import com.westar.base.model.*;
import com.westar.base.pojo.DeptInfo;
import com.westar.base.util.JsoupSelfUtil;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 解析事项基本信息
 */
public class ImplementDetailUtil {

    private static Logger logger = LoggerFactory.getLogger( ImplementDetailUtil.class);

    public static WtaskGeneralBasic getWtaskGeneralBasic(String actCookie, String jsonStr) throws IOException {
        WtaskGeneralBasic wtaskGeneralBasic = new WtaskGeneralBasic();

        JSONObject jsonObject = JSONObject.parseObject(jsonStr);

        //查询页面所需要的参数
        String idForStr = jsonObject.getString("idForStr");

        //rowguid记录唯一标识
        String rowGuid = jsonObject.getString("idForStr");
        wtaskGeneralBasic.setRowGuid(rowGuid);

        //catalogcode基本编码
        String catalogCode = jsonObject.getString("dirListCode");
        wtaskGeneralBasic.setCatalogCode(catalogCode);

        //basecode实施编码
        String baseCode = jsonObject.getString("showEventCode");
        wtaskGeneralBasic.setBaseCode(baseCode);

        //taskname事项名称
        String taskName = jsonObject.getString("eventName");
        wtaskGeneralBasic.setTaskName(taskName);

        //tasktype事项类型
        String taskType = jsonObject.getString("eventType");
        wtaskGeneralBasic.setTaskType(taskType);

        //uselevel行使层级
        String useLevel = jsonObject.getString("performHierarchy");
        wtaskGeneralBasic.setUseLevel(useLevel);
        String useLevelDic = "1.省级;2.市级;3.县级;4.镇（乡、街道）级;5.村（社区）级;6.特殊区域";
        wtaskGeneralBasic.setUseLevelDic(useLevelDic);

        //depttype实施主体性质（见国建事项标准文件）
        String deptType = jsonObject.getString("performDeptType");
        wtaskGeneralBasic.setDeptType(deptType);
        String deptTypeDic = "1.法定机关;2.授权组织;3.受委托组织;";
        wtaskGeneralBasic.setDeptTypeDic(deptTypeDic);

        //deptname实施主体
        String deptName = jsonObject.getString("performDeptName");
        wtaskGeneralBasic.setDeptnName(deptName);

        DeptInfo deptInfo = new DeptInfo();
        String deptCode = jsonObject.getString("deptCode");
        deptInfo.setDeptCod(deptCode);
        deptInfo.setDeptId(jsonObject.getString("deptId"));
        deptInfo.setDeptName(jsonObject.getString("deptName"));
        deptInfo.setDeptSysLevel(jsonObject.getInteger("deptSysLevel"));
        deptInfo.setDeptSysName(jsonObject.getString("deptSysName"));
        wtaskGeneralBasic.setDeptInfo(deptInfo);

        //taskstate事项状态
        String taskState = jsonObject.getString("eventStatus");
        wtaskGeneralBasic.setTaskState(taskState);

        //servertype服务对象
        String serverType = jsonObject.getString("appoveObject");
        wtaskGeneralBasic.setServerType(serverType);
        String serverTypeDic = "1.企业法人;2.自然人;3.其他组织;4.业法人;5.社会组织法人;6.行政机关;7.非法人企业";
        wtaskGeneralBasic.setServerTypeDic(serverTypeDic);

        //projecttype办件类型
        String projectType = jsonObject.getString("appoveTimeLimit");
        wtaskGeneralBasic.setProjectType(projectType);
        String projectTypeDic = "1.即办件;2.承诺件;";
        wtaskGeneralBasic.setProjectTypeDic(projectTypeDic);

        //acceptcondition受理条件
        String acceptCondition = ImplementDetailUtil.getAcceptCondition(actCookie,idForStr);
        wtaskGeneralBasic.setAcceptCondition(acceptCondition);

        //promisetype承诺办结期限
        String promiseType = jsonObject.getString("daysType");;
        wtaskGeneralBasic.setPromiseType(promiseType);
        String promiseTypeDic = "1.工作日;";
        wtaskGeneralBasic.setPromiseTypeDic(promiseTypeDic);

        //promiseday承诺办结时限
        String promiseDay = jsonObject.getString("promiseTimeLimit");
        wtaskGeneralBasic.setPromiseDay(promiseDay);

        //deptcode实施主体编码
        wtaskGeneralBasic.setDeptCode(deptCode);

        //entrustname委托部门X

        //anticipateday法定办结时限
        String anticipateDay = jsonObject.getString("legalTimeLimit");
        wtaskGeneralBasic.setAnticipateDay(anticipateDay);

        //anticipatetype法定办结期限单位
        String anticipateType = jsonObject.getString("clDaysType");
        wtaskGeneralBasic.setAnticipateType(anticipateType);
        String anticipateTypeDic = "1.工作日;";
        wtaskGeneralBasic.setAnticipateType(anticipateTypeDic);

        //isfee是否收费
        String isFee = jsonObject.getString("isCharges");
        wtaskGeneralBasic.setIsFee(isFee);
        String isFeeDic = "1.是;0.否";
        wtaskGeneralBasic.setIsFeeDic(isFeeDic);

        //plancanceldate计划取消日期X
        //planeffectivedate计划生效日期X

        JSONObject serviceInfo = ImplementDetailUtil.getServiceInfo(actCookie,idForStr);
        if(null != serviceInfo){
            //superviseway监督投诉方式
            String superviseWay = serviceInfo.getString("supervisoryTelephone");
            wtaskGeneralBasic.setSuperviseWay(superviseWay);
            //linkway咨询方式
            String linkWay = serviceInfo.getString("cousultingTelephone");
            wtaskGeneralBasic.setLinkWay(linkWay);
            //transactTime办理时段
            String transactTime = serviceInfo.getString("handleTime");
            wtaskGeneralBasic.setTransactTime(transactTime);
            //transactaddr办理地点
            String transactAddr = serviceInfo.getString("handlePlace");
            wtaskGeneralBasic.setTransactAddr(transactAddr);
        }

        //issinglelogin计算机端是否对接单点登录X
        //mobileterminalurl移动端办理地址X

        //cdoperation同步类型X
        //cdbatch批次号X
        //handletype办理形式
        String handleType = jsonObject.getString("doThingType");
        wtaskGeneralBasic.setHandleType(handleType);
        String handleTypeDic = "0.窗口办理;1.网上办理";
        wtaskGeneralBasic.setHandleTypeDic(handleTypeDic);

        //handleflow办理流程X
        //powersource权力来源
        String powerSource = jsonObject.getString("powerSource");
        wtaskGeneralBasic.setPowerSource(powerSource);
        String powerSourceDic = "1.法定本级行使;2.上级下放;3.上级授权;4.同级授权;5.上级委托;6.同级委托;";
        wtaskGeneralBasic.setPowerSourceDic(powerSourceDic);

        //taskhandleitem业务办理项编码X
        //datasource数据来源
        String dataSource = jsonObject.getString("eventSource");
        wtaskGeneralBasic.setDataSource(dataSource);
        //feebasis收费依据X
        //appissinglelogin移动端是否对接单点登录X
        //cdtime同步时间X
        //taskversion事项版本
        String taskVersion = jsonObject.getString("version");
        wtaskGeneralBasic.setTaskVersion(taskVersion);

        //specialprocedure特别程序
        String specialProcedure = jsonObject.getString("specProcedure");
        wtaskGeneralBasic.setSpecialProcedure(specialProcedure);

        //limitscenenum到办事现场次数
        String limitSceneNum = jsonObject.getString("percenceTimes");
        wtaskGeneralBasic.setLimitSceneNum(limitSceneNum);

        //updatetime--
        String updateTime = jsonObject.getString("updateTime");
        wtaskGeneralBasic.setUpdateTime(updateTime);
        //anticipateexplain法定办结时限说明X
        //promiseexplain承诺办结时限说明X
        //linkaddr计算机端在线办理跳转地址X
        //cdsign同步标识X
        //onlineaddress网上办理地址
        String onLineAddress  = jsonObject.getString("onlineHandleUrl");
        wtaskGeneralBasic.setOnLineAddress(onLineAddress);
        //onlineflowexplain网上办理流程说明X
        //onlineflowguid网上办理流程X
        //handleflowguid--X
        //sync--X
        //publishstatus--X
        //ensitivestatus--X
        //ywsign--X
        //istaskhandleitem是否有业务办理项编码X
        //reconsiderouname行政复议部门名称X
        //reconsideraddress行政复议地址X
        //reconsidercontact行政复议联系方式X
        //litigationouname行政诉讼部门名称X
        //litigationaddress行政诉讼地址X
        //litigationcontact行政诉讼联系方式X
        //punishmentmethod处罚的行为、种类、幅度X
        //collecttype征收种类X
        //ispermitreduce是否涉及征收(税)费减免的审批X
        return wtaskGeneralBasic;
    }

    /**
     * 取得服务信息
     * @param actCookie
     * @param idForStr
     * @return
     * @throws IOException
     */
    private static JSONObject getServiceInfo(String actCookie,String idForStr) throws IOException {
        List<String> acceptConditionList = ImplementPageUtil.listImplementBaseServiceInfo(actCookie,idForStr);
        if(null != acceptConditionList && !acceptConditionList.isEmpty()){
            String result = acceptConditionList.get(0);
            JSONObject jsonObject = JSONObject.parseObject(result);
            return jsonObject;
        }
        return null;
    }

    /**
     * 受理条件
     *
     * @param actCookie
     * @return
     */
    private static String getAcceptCondition(String actCookie,String idForStr) throws IOException {
        //受理条件信息
        List<String> acceptConditionList = ImplementPageUtil.listImplementBaseAcceptCondition(actCookie,idForStr);
        String result = "";
        if(null != acceptConditionList && !acceptConditionList.isEmpty()){
            for (String conditionStr:acceptConditionList) {
                JSONObject jsonObject = JSONObject.parseObject(conditionStr);
                result = result + jsonObject.getString("permissiveCondition")+"\n";
            }
        }
        return result;
    }

    /**
     * 取得扩展信息
     * @param actCookie
     * @param jsonStr
     * @return
     */
    public static WtaskGeneralExtend getWtaskGeneralExtend(String actCookie, String jsonStr) throws IOException {
        WtaskGeneralExtend wtaskGeneralExtend = new WtaskGeneralExtend();

        JSONObject jsonObject = JSONObject.parseObject(jsonStr);

        String idForStr = jsonObject.getString("idForStr");
        String shardKey = jsonObject.getString("shardKey");

        String responeBody = ImplementPageUtil.viewImplementBaseDetail(actCookie,idForStr,shardKey);

        Document doc = Jsoup.parse(responeBody);
        Elements parentEle = doc.select("#basicInfo");

        //taskGuid记录唯一标识
        String taskGuid = jsonObject.getString("idForStr");
        wtaskGeneralExtend.setTaskGuid(taskGuid);

        //basecode实施编码
        String baseCode = jsonObject.getString("showEventCode");
        wtaskGeneralExtend.setBaseCode(baseCode);

        //isentrycenter是否进驻政务大厅
        String isEntryCenter = jsonObject.getString("isGoveCenter");
        wtaskGeneralExtend.setIsEntryCenter(isEntryCenter);
        String isEntryCenterDic = "1.是;0.否";
        wtaskGeneralExtend.setIsEntryCenterDic(isEntryCenterDic);

        //handlearea通办范围
        String handleArea = jsonObject.getString("operatScope");
        wtaskGeneralExtend.setHandleArea(handleArea);
        String handleAreaDic = "1.全国;0.跨省;3.跨市;4.跨县;5.跨镇（乡、街道）;6.跨村（社区）";
        wtaskGeneralExtend.setHandleAreaDic(handleAreaDic);

        //otherdept联办机构
        String otherdept = jsonObject.getString("jointagency");
        wtaskGeneralExtend.setOtherDept(otherdept);

        //servicetype中介服务
        String serviceType = ImplementDetailUtil.agencyServiceList(actCookie,idForStr);
        wtaskGeneralExtend.setServiceType(serviceType);

        //resulttype审批结果类型
        String resultType = jsonObject.getString("applyresultType");
        wtaskGeneralExtend.setResultType(resultType);
        String resultTypeDic = "10.证照;20.批文;30.其他;99.无;";
        wtaskGeneralExtend.setResultTypeDic(resultTypeDic);

        //resultname审批结果名称
        String resultName = jsonObject.getString("handleResultForm");
        wtaskGeneralExtend.setResultName(resultName);

        //isschedule是否支持预约办理
        String isSchedule = jsonObject.getString("isOnlineSubscribe");
        wtaskGeneralExtend.setIsSchedule(isSchedule);
        String isScheduleDic = "1.是;0.否";
        wtaskGeneralExtend.setIsScheduleDic(isScheduleDic);

        //ispayonline是否支持网上支付
        String isPayOnline = jsonObject.getString("isOnlinePay");
        wtaskGeneralExtend.setIsPayOnline(isPayOnline);
        String isPayOnlineDic = "1.是;0.否";
        wtaskGeneralExtend.setIsPayOnlineDic(isPayOnlineDic);

        //isexpress是否支持物流快递
        String isExpress = jsonObject.getString("isExpressTake");
        wtaskGeneralExtend.setIsExpress(isExpress);
        String isExpressDic = "1.是;0.否";
        wtaskGeneralExtend.setIsExpressDic(isExpressDic);

        //isserviceterminals是否支持自助终端办理X

        //limitsceneexplain必须现场办理原因说明
        String limitSceneExplain = null;

        Elements basicInfoFormEle = parentEle.select("#basicInfoForm");
        if(null!=basicInfoFormEle && !basicInfoFormEle.isEmpty()){
            Elements tableEle = basicInfoFormEle .select("table");
            if(null!=tableEle && !tableEle.isEmpty()){
                Elements jointagencyEle = tableEle.select("#jointagency");
                if(null!=jointagencyEle && !jointagencyEle.isEmpty()){
                    Element staticElementTr = jointagencyEle.get(0);
                    while(!staticElementTr.tagName().toLowerCase().equals("tr")){
                        staticElementTr = staticElementTr.parent();
                    }

                    Element nextEle = staticElementTr.nextElementSibling();
                    while(null != nextEle ){
                        String customTitle = nextEle.select(".customTitle").text();
                        if(StringUtils.trim(customTitle).equals("必须现场办理原因说明")){
                            Elements limitSceneExplainEle = nextEle.select("input");
                            if(null!=limitSceneExplainEle && !limitSceneExplainEle.isEmpty()){
                                limitSceneExplain = nextEle.select("input").attr("value");
                            }
                            break;
                        }
                        nextEle = nextEle.nextElementSibling();
                    }
                }
            }
        }

        wtaskGeneralExtend.setLimitSceneExplain(limitSceneExplain);

        //limitexplain数量限制
        String limitExplain = jsonObject.getString("numberLimit");
        wtaskGeneralExtend.setLimitExplain(limitExplain);

        //extendfield扩展字段X
        //cdoperation同步类型X
        //cdbatch批次号X
        //taskhandleitem业务办理项编码X

        //datasource数据来源
        String dataSource = jsonObject.getString("eventSource");
        wtaskGeneralExtend.setDataSource(dataSource);

        //resultguid审批结果样本（页面上 sampleFileList）
        String resultGuid = ImplementDetailUtil.sampleFileList(actCookie,idForStr);
        wtaskGeneralExtend.setResultGuid(resultGuid);

        //usertopictype面向自然人事项主题分类
        String userTopicType = jsonObject.getString("onlineItemType");
        wtaskGeneralExtend.setUserTopicType(userTopicType);

        //usercharactertopictype面向自然人地方特色主题分类
        String  userCharacterTopicType = jsonObject.getString("onlineItemType") ;

        String userCharacterTopicTypeName = "";
        Elements onlineItemTypeEle = parentEle.select("#onlineItemType");
        if(null != onlineItemTypeEle && !onlineItemTypeEle.isEmpty()){
            Element onlineItemTypeParentEle = onlineItemTypeEle.get(0).parent();
            Elements  tagboxLabelElement = onlineItemTypeParentEle.select(".tagbox-label");
            if(null != tagboxLabelElement && !tagboxLabelElement.isEmpty()){
                userCharacterTopicTypeName = tagboxLabelElement.text();
            }
        }
        userCharacterTopicType = userCharacterTopicType+"_" + userCharacterTopicTypeName;
        wtaskGeneralExtend.setUserCharacterTopicType(userCharacterTopicType);
        //corptopictype面向法人事项主题分类X
        //corpcharactertopictype面向法人地方特色主题分类X

        //townname乡镇街道名称X
        //towncode乡镇街道代码X
        //villagename村居社区名称X
        //villagecode村居社区代码X
        //cdtime同步时间X

        //onlinehandledepth网上办理深度
        Elements onlineHandleDepthEle = parentEle.select("[name='onlineProceDepth']");
        String onlineHandleDepth = JsoupSelfUtil.getCheckBoxVal(onlineHandleDepthEle);
        wtaskGeneralExtend.setOnlineHandleDepth(onlineHandleDepth);
        String onlineHandleDepthDic = "1.互联网咨询;2.互联网收件;3.互联网预审;4.互联网受理;5.互联网办理;6.互联网结果反馈;7.其他;";
        wtaskGeneralExtend.setOnlineHandleDepthDic(onlineHandleDepthDic);
        //updatetime--
        String updateTime = jsonObject.getString("updateTime");
        wtaskGeneralExtend.setUpdateTime(updateTime);
        //isonline是否网办
        String  isOnline = jsonObject.getString("onlineType");
        wtaskGeneralExtend.setIsOnline(isOnline);
        String isOnlineDic = "0.原件预审';1.原件核验;2.全程网办";
        wtaskGeneralExtend.setIsOnlineDic(isOnlineDic);

        //onlinehandleurl网办地址
        String onlineHandleUrl  = jsonObject.getString("onlineHandleUrl");
        wtaskGeneralExtend.setOnlineHandleUrl(onlineHandleUrl);

        //applicationrights申请人权利X
        //applicationobligation申请人义务X
        //resultexplain审批结果说明X
        //resultschedule审批进度及结果查询方式X
        //sensitivestatus--X
        return   wtaskGeneralExtend;
    }

    /**
     * 中介机构信息
     * @param actCookie
     * @return
     */
    private static String agencyServiceList(String actCookie,String idForStr) throws IOException {
        //中介机构信息
        List<String> list = ImplementPageUtil.agencyServiceList(actCookie,idForStr);
        Gson gson = new Gson();
        return gson.toJson(list);
    }

    /**
     * 审批加过样表信息
     * @param actCookie
     * @param idForStr
     * @return
     * @throws IOException
     */
    private static String sampleFileList(String actCookie,String idForStr) throws IOException {
        List<String> list = ImplementPageUtil.sampleFileList(actCookie,idForStr);
        List<String> result = new ArrayList<String>();
        if(null != list && !list.isEmpty()){
            for (String fileInfoStr:list) {
                JSONObject jsonObject = JSONObject.parseObject(fileInfoStr);
                String attachmentsId = jsonObject.getString("attachmentsId");
                String shardKey = jsonObject.getString("attachmentsId");
                String fileUrl = "http://"+ SysConst.DOMAIN+"/attachment/download?id="+attachmentsId;
                if(StringUtils.isNotEmpty(shardKey)){
                    fileUrl = fileUrl+"&shardKey="+shardKey;
                }
                result.add(fileUrl);
            }
        }
        Gson gson = new Gson();
        return gson.toJson(result);
    }

    /**
     * 查询法定依据信息
     * @param actCookie
     * @param jsonStr
     * @return
     */
    public static List<WtaskGeneralLaw> getWtaskGeneralLaws(String actCookie, String jsonStr) throws IOException {
        List<WtaskGeneralLaw> list = new ArrayList<>();
        JSONObject jsonObjectForId = JSONObject.parseObject(jsonStr);

        String idForStr = jsonObjectForId.getString("idForStr");
        List<String> result = ImplementPageUtil.queryLawRegulations(actCookie,idForStr);
        if(null == result || result.isEmpty()){
            return list;
        }

        //查询法定依据信息
        for (String object : result) {
            WtaskGeneralLaw wtaskGeneralLaw = new WtaskGeneralLaw();

            JSONObject jsonObject = JSONObject.parseObject(object.toString());
            //rowguid记录唯一标识
            String rowGuid = jsonObject.getString("idForStr");
            wtaskGeneralLaw.setRowGuid(rowGuid);
            //catalogguid基本目录标识X
            //lawname法律名称
            String lawName = jsonObject.getString("lawName");
            wtaskGeneralLaw.setLawName(lawName);
            //accordingnumber依据文号
            String accordingNumber = jsonObject.getString("referenceNum");
            wtaskGeneralLaw.setAccordingNumber(accordingNumber);
            //termsnumber条款号
            String termsNumber = jsonObject.getString("clause");
            wtaskGeneralLaw.setTermsContent(termsNumber);
            //termscontent条款内容
            String termsContent = jsonObject.getString("clauseContent");;
            wtaskGeneralLaw.setTermsContent(termsContent);
            //ordernumber序号X
            //implementationdate实施日期X
            //issuingorgan颁发机关X
            //cdtime同步时间X
            //cdbatch--X
            //datasource--X
            //sensitivestatus--X
            list.add(wtaskGeneralLaw);
        }
        return list;
    }

    /**
     * 收费项目信息
     * @param actCookie
     * @param jsonStr
     * @return
     */
    public static List<WtaskGeneralFeeProject> getWtaskGeneralFeeProject(String actCookie, String jsonStr) throws IOException {
        List<WtaskGeneralFeeProject> list = new ArrayList<>();
        //查询收费项目信息
        JSONObject jsonObjectForId = JSONObject.parseObject(jsonStr);

        String idForStr = jsonObjectForId.getString("idForStr");
        List<String> result = ImplementPageUtil.queryChargeInfoList(actCookie,idForStr);
        if(null == result || result.isEmpty()){
            return list;
        }
        String responeBody = "";
        JSONArray jsonArray = new JSONArray();
        for (Object object : jsonArray) {
            WtaskGeneralFeeProject wtaskGeneralFeeProject = new WtaskGeneralFeeProject();
            JSONObject jsonObject = JSONObject.parseObject(object.toString());
            //remark备注
            //rowguid记录唯一标识
            String rowGuid = jsonObject.getString("idForStr");
            wtaskGeneralFeeProject.setRowGuid(rowGuid);
            //taskcode实施编码
            //taskguid事项唯一标识
            //ordernum排序

            //feename收费项目名称
            String feeName = jsonObject.getString("chargeProject");
            wtaskGeneralFeeProject.setFeeName(feeName);

            //feestand收费标准
            String feeStand = jsonObject.getString("chargeStandard");
            wtaskGeneralFeeProject.setFeeStand(feeStand);

            //isdesc是否允许减免
            //descexplain允许减免依据
            //cdoperation同步类型
            //cdbatch批次号
            //bylaw收费依据
            //taskhandleitem业务办理项编码
            //datasource数据来源
            //cdtime同步时间
            //updatetime
            String updateTime = jsonObject.getString("updateTime");
            wtaskGeneralFeeProject.setUpdateTime(updateTime);
            //sensitivestatus


            list.add(wtaskGeneralFeeProject);
        }
        return list;
    }

    /**
     * 查询事项情形材料分类
     * @param actCookie
     * @param jsonStr
     * @return
     */
    public static List<WtaskGeneralMaterialcase> getWtaskGeneralMaterialcase(String actCookie, String jsonStr) throws IOException {
        List<WtaskGeneralMaterialcase> list = new ArrayList<>();
        JSONObject jsonObjectForId = JSONObject.parseObject(jsonStr);

        String idForStr = jsonObjectForId.getString("idForStr");
        List<String> result = null;
        if(null == result || result.isEmpty()){
            return list;
        }
        //查询事项情形材料分类
        for (String object : result) {
            WtaskGeneralMaterialcase wtaskGeneralMaterialcase = new WtaskGeneralMaterialcase();
            JSONObject jsonObject = JSONObject.parseObject(object);

            //rowguid记录唯一标识
            String rowGuid = jsonObject.getString("idForStr");
            wtaskGeneralMaterialcase.setRowGuid(rowGuid);

            //taskguid事项标识
            wtaskGeneralMaterialcase.setTaskGuid(idForStr);

            //conditionguid情形标识
            //conditionname情形名称
            //materialguid材料标识
            //cdoperation同步类型
            //cdbatch批次号
            //cdtime同步时间
            //cdsign同步标识
            //datasource--
            //sensitivestatus--
            list.add(wtaskGeneralMaterialcase);
        }
        return list;
    }

    /**
     * 查询常见问题解答
     * @param actCookie
     * @param jsonStr
     * @return
     */
    public static List<WtaskGeneralQuestions> getWtaskGeneralQuestions(String actCookie, String jsonStr) throws IOException {
        List<WtaskGeneralQuestions> list = new ArrayList<>();
        JSONObject jsonObjectForId = JSONObject.parseObject(jsonStr);

        String idForStr = jsonObjectForId.getString("idForStr");
        List<String> result = ImplementPageUtil.queryFaqList(actCookie,idForStr);
        if(null == result || result.isEmpty()){
            return list;
        }
        //查询常见问题解答
        for (String object : result) {
            WtaskGeneralQuestions wtaskGeneralMaterialcase = new WtaskGeneralQuestions();
            JSONObject jsonObject = JSONObject.parseObject(object.toString());

            //rowguid记录唯一标识
            String rowGuid = jsonObject.getString("idForStr");
            wtaskGeneralMaterialcase.setRowGuid(rowGuid);

            //taskcode实施编码
            //taskguid事项唯一标识
            wtaskGeneralMaterialcase.setTaskGuid(idForStr);

            //ordernum排序
            //question问题
            String question = jsonObject.getString("question");
            wtaskGeneralMaterialcase.setQuestion(question);

            //answer解答
            String answer = jsonObject.getString("answer");
            wtaskGeneralMaterialcase.setAnswer(answer);

            //cdoperation同步类型
            //cdbatch批次号
            //taskhandleitem业务办理项编码
            //datasource数据来源
            //cdtime同步时间

            //updatetime--
            String updateTime = jsonObject.getString("updateTime");
            wtaskGeneralMaterialcase.setUpdateTime(updateTime);

            //sensitivestatus--

            list.add(wtaskGeneralMaterialcase);
        }
        return list;
    }

    /**
     * 材料信息
     * @param actCookie
     * @param jsonStr
     * @return
     */
    public static List<WtaskGeneralMaterial> getWtaskGeneralMaterial(String actCookie, String jsonStr) throws IOException {
        List<WtaskGeneralMaterial> list = new ArrayList<>();

        JSONObject jsonObjectForId = JSONObject.parseObject(jsonStr);

        String idForStr = jsonObjectForId.getString("idForStr");
        List<String> result = ImplementPageUtil.queryMaterialListV2(actCookie,idForStr);
        if(null == result || result.isEmpty()){
            return list;
        }
        //查询材料信息
        for (String object : result) {
            WtaskGeneralMaterial wtaskGeneralMaterial = new WtaskGeneralMaterial();
            JSONObject jsonObject = JSONObject.parseObject(object);
            //remark备注
            String remark = jsonObject.getString("realRemark");
            wtaskGeneralMaterial.setRemark(remark);

            //rowguid记录唯一标识
            String rowGuid = jsonObject.getString("idForStr");
            wtaskGeneralMaterial.setRowGuid(rowGuid);

            //taskcode实施编码
            //taskguid事项唯一标识

            //materialname材料名称
            String materialName = jsonObject.getString("materialName");
            wtaskGeneralMaterial.setMaterialName(materialName);

            //materialtype材料类型
            String materialType = jsonObject.getString("materialCategory");
            wtaskGeneralMaterial.setMaterialType(materialType);
            String materialTypeDic = "1.原件和复印件;2.原件;3.复印件;4.其他;";
            wtaskGeneralMaterial.setMaterialTypeDic(materialTypeDic);

            //isneed材料必要性
            String isNeed = jsonObject.getString("isMust");
            wtaskGeneralMaterial.setIsNeed(isNeed);
            String isNeedDic = "1.是;0.否;";
            wtaskGeneralMaterial.setIsNeedDic(isNeedDic);

            String isFreshSeal = jsonObject.getString("isFreshSeal");
            wtaskGeneralMaterial.setIsFreshSeal(isFreshSeal);
            String isFreshSealDic = "1.是;0.否;";
            wtaskGeneralMaterial.setIsFreshSealDic(isFreshSealDic);

            //sourceexplain来源渠道说明
            String sourceExplain = jsonObject.getString("sourceOfMaterial");
            wtaskGeneralMaterial.setSourceExplain(sourceExplain);

            //pagenum纸质材料份数
            String paperNum = jsonObject.getString("paperNum");
            wtaskGeneralMaterial.setPaperNum(paperNum);

            //pageformat纸质材料规格
            String pageFormat = jsonObject.getString("paperMaterStandard");
            wtaskGeneralMaterial.setPageFormat(pageFormat);

            //fillexplain填报须知
            String fillExplain = jsonObject.getString("deliverDemand");
            wtaskGeneralMaterial.setFillExplain(fillExplain);

            //acceptstand受理标准
            String acceptStand = jsonObject.getString("remark");
            wtaskGeneralMaterial.setAcceptStand(acceptStand);

            //ordernum排序
            //cdoperation同步类型
            //cdbatch批次号
            //bylaw设定依据
            //sourcetype来源渠道
            String sourceType = jsonObject.getString("materialType");
            wtaskGeneralMaterial.setSourceType(sourceType);
            String sourceTypeDic = "1.申请人自备;2.其他;3.政府部门核发;";
            wtaskGeneralMaterial.setSourceTypeDic(sourceTypeDic);

            //materialformat材料形式
            String materialformat = jsonObject.getString("materialForm");
            wtaskGeneralMaterial.setMaterialFormat(materialformat);
            String materialformatDic = "1.是;0.否;";
            wtaskGeneralMaterial.setMaterialFormatDic(materialformatDic);

            //taskhandleitem业务办理项编码
            //datasource数据来源

            //formguid空白表格
            //exampleguid示例样表
            //cdtime同步时间

            //updatetime--
            String updatetime = jsonObject.getString("updateTime");
            wtaskGeneralMaterial.setUpdateTime(updatetime);

            //papermaterialtype纸质材料类型
            //masternum原件份数
            //copynum复印件份数
            //sensitivestatus--

            //材料信息
            String materialId = jsonObject.getString("referenceId");

            String responeBody = ImplementPageUtil.viewMaterial(actCookie,rowGuid);
            Document doc = Jsoup.parse(responeBody);
            String textName = doc.select("#materialForm > .table_details_list > tbody > tr:eq(1) > td:eq(0)").text();
            if(textName.indexOf("材料属性") >=0 ){
                String textVale = doc.select("#materialForm > .table_details_list > tbody > tr:eq(1) > td:eq(1)").text();
                if(null != textVale){
                    textVale = textVale.replaceAll(" ","");
                }
                wtaskGeneralMaterial.setMaterialProperty(textVale);
            }
//                    ImplementPageUtil.queryMaterialId(actCookie,rowGuid);
            JSONArray materialItemData = ImplementPageUtil.listMaterialItemData(actCookie,materialId);
            wtaskGeneralMaterial.setMaterialItemList(materialItemData.toJSONString());

            list.add(wtaskGeneralMaterial);
        }
        return list;
    }

    /**
     * 审查要点信息
     * @param actCookie
     * @param jsonStr
     * @return
     * @throws IOException
     */
    public static List<WtaskGeneralCheckTip> getWtaskGeneralCheckTip(String actCookie, String jsonStr) {
        List<WtaskGeneralCheckTip> list = new ArrayList<WtaskGeneralCheckTip>();

        JSONObject jsonObjectForId = JSONObject.parseObject(jsonStr);

        String idForStr = jsonObjectForId.getString("idForStr");
        List<String> result = null;
        try {
            result = ImplementPageUtil.queryReviewDetail(actCookie,idForStr);
            logger.error("result.size()->" + result.size() );
        } catch (IOException e) {
            logger.error( e.getMessage() );
        }
        if(null == result || result.isEmpty()){
            return list;
        }
        //查询材料信息
        for (String object : result) {
            WtaskGeneralCheckTip wtaskGeneralCheckTip = new WtaskGeneralCheckTip();
            JSONObject jsonObject = JSONObject.parseObject(object);

            String rowGuid = jsonObject.getString("idForStr");
            wtaskGeneralCheckTip.setRowGuid(rowGuid);

            String content = jsonObject.getString("reviewContent");
            wtaskGeneralCheckTip.setContent(content);

            String tips = jsonObject.getString("reviewPoints");
            wtaskGeneralCheckTip.setTips(tips);

            String standard = jsonObject.getString("reviewStandard");
            wtaskGeneralCheckTip.setStandard(standard);

            String attentions = jsonObject.getString("attentions");
            wtaskGeneralCheckTip.setAttentions(attentions);

            list.add(wtaskGeneralCheckTip);
        }
        return list;

    }

    /**
     * 自由裁量
     * @param actCookie
     * @param jsonStr
     * @return
     * @throws IOException
     */
    public static List<WtaskGeneralDiscretion> getWtaskGeneralDiscretion(String actCookie, String jsonStr) throws IOException {
        List<WtaskGeneralDiscretion> list = new ArrayList<WtaskGeneralDiscretion>();

        JSONObject jsonObjectForId = JSONObject.parseObject(jsonStr);

        String idForStr = jsonObjectForId.getString("idForStr");
        List<String> result = ImplementPageUtil.queryPunishListNoPage(actCookie,idForStr);
        if(null == result || result.isEmpty()){
            return list;
        }
        //查询材料信息
        for (String object : result) {
            WtaskGeneralDiscretion wtaskGeneralDiscretion = new WtaskGeneralDiscretion();
            JSONObject jsonObject = JSONObject.parseObject(object);

            String rowGuid = jsonObject.getString("idForStr");
            wtaskGeneralDiscretion.setRowGuid(rowGuid);

            String performHierarchy = jsonObject.getString("performHierarchy");
            wtaskGeneralDiscretion.setPerformHierarchy(performHierarchy);
            String performHierarchyDic = "1.省级;2.市级;3.县级;4.镇（乡、街道）级;5.村（社区）级;6.特殊区域;";
            wtaskGeneralDiscretion.setPerformHierarchyDic(performHierarchyDic);

            String plotDesc = jsonObject.getString("plotDesc");
            wtaskGeneralDiscretion.setPlotDesc(plotDesc);

            String punishType = jsonObject.getString("punishType");
            wtaskGeneralDiscretion.setPunishType(punishType);
            String  punishTypeDic = "1.警告;2.罚款;3.没收违法所得;4.没收非法财物;5.责令停产停业;6.暂扣或吊销许可证;7.暂扣或吊销执照;8.行政拘留;9.其他行政处罚;";
            wtaskGeneralDiscretion.setPunishTypeDic(punishTypeDic);

            String fineUpperLimt = jsonObject.getString("fineUpperLimt");
            wtaskGeneralDiscretion.setFineUpperLimt(fineUpperLimt);

            String fineLowerLimt = jsonObject.getString("fineLowerLimt");
            wtaskGeneralDiscretion.setFineLowerLimt(fineLowerLimt);

            String fineRemark = jsonObject.getString("fineRemark");
            wtaskGeneralDiscretion.setFineRemark(fineRemark);

            String mswfsd = jsonObject.getString("mswfsd");
            wtaskGeneralDiscretion.setMswfsd(mswfsd);

            String msffcw = jsonObject.getString("msffcw");
            wtaskGeneralDiscretion.setMsffcw(msffcw);

            String eventName = jsonObject.getString("eventName");
            wtaskGeneralDiscretion.setEventName(eventName);

            list.add(wtaskGeneralDiscretion);
        }
        return list;
    }
}
